#include "tvoeradio.h"

TvoeRadio::TvoeRadio(int &argc, char **argv) : QApplication(argc, argv)
{
    updateProxyConfig();
    constructOp();
}

TvoeRadio::~TvoeRadio()
{
    destructOp();
}

void TvoeRadio::updateProxyConfig()
{
    QSettings settings;
    QNetworkProxy proxy;
    settings.beginGroup("Network");
    if (settings.value("Proxy", false).toBool()) {
        switch (settings.value("ProxyType", false).toInt()) {
        case 0: proxy.setType(QNetworkProxy::Socks5Proxy); break;
        case 1: proxy.setType(QNetworkProxy::HttpProxy); break;
        default: proxy.setType(QNetworkProxy::NoProxy); break;
        }
        proxy.setHostName(settings.value("ProxyHost").toString());
        proxy.setPort(settings.value("ProxyPort").toInt());
        proxy.setUser(settings.value("ProxyUser").toString());
        proxy.setPassword(settings.value("ProxyPassword").toString());
    } else {
        proxy.setType(QNetworkProxy::NoProxy);
    }
    settings.endGroup();
    QNetworkProxy::setApplicationProxy(proxy);
}
